package com.jiunuan.live.api.controller;

import com.jiunuan.live.user.dto.UserDTO;
import com.jiunuan.live.user.interfaces.IUserRpc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/user")
@Tag(name = "UserController-用户相关接口")
public class UserController {

    @DubboReference
    private IUserRpc userRpc;

    @Operation(summary = "getUserInfo-获取用户信息")
    @GetMapping("/getUserInfo")
    public UserDTO getUserInfo(Long userId) {
        return userRpc.getUserById(userId);
    }
    @Operation(summary = "updateUserInfo-更新用户信息")
    @GetMapping("/updateUserInfo")
    public boolean updateUserInfo(UserDTO userDTO) {
        return userRpc.updateUserInfo(userDTO);
    }
    @Operation(summary = "insertUserInfo-插入用户信息")
    @GetMapping("/insertUserInfo")
    public boolean insertUserInfo(UserDTO userDTO) {
        return userRpc.insertOne(userDTO);
    }
    @Operation(summary = "batchQueryUserInfo-批量查询用户信息")
    @GetMapping("/batchQueryUserInfo")
    public Map<Long, UserDTO> batchQueryUserInfo(String userIdStr) {
        return userRpc.batchQueryUserInfo(Arrays.asList(userIdStr.split(","))
                .stream().map(Long::valueOf).collect(Collectors.toList()));
    }
}